import 'package:flutter/material.dart';
import 'package:jtsell_app/provider/test_counter_model.dart';
import 'package:provider/provider.dart';


class CategoryPage extends StatelessWidget {
  final counter = CounterModel();

  @override
  Widget build(BuildContext context) {
    return ChangeNotifierProvider<CounterModel>.value(value: counter, child: CountWidget());
  }
}


class CountWidget extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: Text("分类"),
        ),
        body: Row(
          children: <Widget>[ButtonWidget(), TextWidget()],
        ));
  }
}

class ButtonWidget extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    final _counterModel = Provider.of<CounterModel>(context);

    return Center(
      child: FlatButton.icon(
          icon: Icon(Icons.add),
          label: Text("点我 +1"),
          onPressed: () {
            _counterModel.increment();
          }),
    );
  }
}

class TextWidget extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Center(
      child:
          Consumer<CounterModel>(builder: (BuildContext context, CounterModel value, Widget child) {
        return Text("${value.count}");
      }),
    );
  }
}

